<template>
	<view class="content">
		<view class="placeholder"></view>
		<u-navbar bgColor="#0a0a22">
			<view class="u-nav-slot" slot="left">
				<view class="logo"><image :style="{width:`320rpx`}" class="img" src="../../static/images/common/headerLogo.png" mode="widthFix"></image></view>
			</view>
		</u-navbar>
		<view class="notice">
			<u-notice-bar @click="onClickNotice" :text="noticeList" direction="column" bgColor="#353446" color="#ffffff" icon="/static/images/home/icon-notice.png"></u-notice-bar>
		</view>
		<view class="swiper">
			<u-swiper height="200" :list="adList" indicator indicatorMode="line" circular radius="10" bgColor="#0a0a22"></u-swiper>
		</view>
		<view class="market">
			<view class="market__col" @click="navTo('/pages/market/index', {marketType: 0})">
				<image class="img" src="../../static/images/home/market_type0.png" mode="widthFix"></image>
				<view class="label">
					<text>版权品市场</text>
				</view>
			</view>
			<view class="market__col" @click="navTo('/pages/market/index', {marketType: 1})">
				<image class="img" src="../../static/images/home/market_type1.png" mode="widthFix"></image>
				<view class="label">
					<text>衍生品市场</text>
				</view>
			</view>
		</view>
		<category />
		<artist />
		<collection />
	</view>
</template>

<script>
	import { mapState, mapGetters, mapActions, mapMutations } from 'vuex'
	import category from '../home/components/category'
	import artist from '../home/components/artist'
	import collection from '../home/components/collection'
	import {checkUpdate} from "@/components/yzhua006-update/js/app-update-check.js";
	
	export default {
		components: {
			category,
			artist,
			collection
		},
		data() {
			return {
				adList: [],
				noticeList: [],
				notices: [],
				Appinfor: {
					vsCode: null,
					vsName: null,
					showBage:false,
					force:0,
				}						
			}
		},
		onLoad() {
			this.getAdList({type: 1}).then(res => {
				this.adList = res.rows
			})
			this.getNoticeList().then(res => {
				if(res.total > 0){
					this.notices = res.rows
					this.noticeList = res.rows.map(item => item.title)
				}
			})
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, widgetInfo => {
				this.Appinfor.vsCode = widgetInfo.versionCode;
				this.Appinfor.vsName = widgetInfo.versionName;
				this._versionApp();
			});
			// #endif
		},
		methods: {
			...mapActions("home", ["getAdList", "getNoticeList"]),
			...mapActions('common', ['versionApp']),
			onClickNotice(index){
				this.navTo('/pages/home/noticeDetail', {id: this.notices[index].id})
			},
			_versionApp() {
				this.versionApp().then(res => {
					if(this.Appinfor.vsCode < res.data.versionCode){
						this.getAppInfo(0,res);
					}
				})
			},
			getAppInfo(type,res) {
				const system_info = uni.getSystemInfoSync();
				let params = {
					os: system_info.platform //本机设备操作系统  （android || ios）
				}
				if (params.os != 'ios' && params.os != 'android') false; //如果不是安卓或ios 返回false
			
				//这里自行请求API获取版本信息 建议传入操作系统标识，返回本机对应的操作系统最新版本信息，也就是安卓的返回就是安卓的版本信息  ios返回就是ios的版本信息
				//请求获取最新版本
				let update_info = {
					version: res.data.versionName, //线上版本
					now_url: params.os == 'android' ? res.data.androidUrl : res.data.iosUrl, //更新链接
					silent: 0, //是否是静默更新
					force: res.data.forceUpdate, //是否是强制更新
					net_check: 1, //非WIfi是否提示
					note: res.data.versionInfo, //更新内容
				}
				checkUpdate(update_info, type).then(res => {
					if (res.msg) {
						plus.nativeUI.toast(res.msg);
					}
				}); ///检查更新
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		padding: 0 10rpx;
		// #ifdef APP-PLUS
		padding-top: 100rpx;
		// #endif
		
	}
	.u-nav-slot{
		
		.logo{
			color: #ffffff;
			font-size: 40rpx;
			font-weight: bold;
			display: flex;
			// justify-content: space-between;
			align-items: center;
		}
	}
	.placeholder{
		/* #ifdef APP-PLUS */
		height:var(--status-bar-height); 
		/* #endif */
		/* #ifdef H5 */
		height:88rpx;
		/* #endif */
	}
	.notice{
		margin: 20rpx 0;
	}
	.market{
		display: flex;
		justify-content: space-between;
		margin-top: 30rpx;
		&__col{
			width: 48%;
			position: relative;
			.img{
				width: 100%;
				border-radius: 10rpx;
			}
			.label{
				position: absolute;
				bottom: 40rpx;
				left: 30rpx;
				font-weight: bold;
			}
		}
	}
	.u-notice-bar{
		border-radius: 6rpx;
	}
</style>
